package com.uhylab.uhuvinetest.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.uhylab.uhuvinetest.R;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.ArrayList;

/**
 * 项目名称：Uhylab
 * 类描述：
 * 创建人：xyb
 * 创建时间：16/6/3 14:31
 * 修改人：xyb
 * 修改时间：16/6/3 14:31
 * 修改备注：
 */
public class UHLineListAdapter extends BaseAdapter {

    private Context mContext;
    private ArrayList<String> mStrings;


    public UHLineListAdapter(Context context, ArrayList<String> strings) {
        mContext = context;
        mStrings = strings;
    }

    @Override
    public int getCount() {
        return mStrings != null && mStrings.size() > 0 ? mStrings.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return mStrings != null && mStrings.size() > 0 ? mStrings.get(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return mStrings != null && mStrings.size() > 0 ? position : 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = View.inflate(mContext, R.layout.line_list_item, null);
            holder.line_list_text = (TextView) convertView.findViewById(R.id.line_list_text);
            convertView.setTag(holder);

            //对于listview，注意添加这一行，即可在item上使用高度
            AutoUtils.autoSize(convertView);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        String text = (String) getItem(position);
        holder.line_list_text.setText(text);

        return convertView;
    }


    private class ViewHolder {
        TextView line_list_text;
    }
}
